package b.cif.impl

import b.utils.entity.ACPersistentEntity
import play.api.libs.json.{Format, Json}

case class CC当前序号(v序号: Int)
object CC当前序号 {
  implicit val format1: Format[CC当前序号] = Json.format
}

class C客户号PersistentEntity extends ACPersistentEntity {

  override type Command = CC申请客户号Command
  override type Event = CC当前序号
  override type State = Int

  override def initialState: State = 1

  override def behavior: Behavior = {
    Actions().onCommand[CC申请客户号Command, Int] {
      case (cmd: CC申请客户号Command, ctx, state) =>
        ctx.thenPersist(CC当前序号(state + 1))(_ => ctx.reply(state))
    }.onEvent {
      case (event: CC当前序号, _) => event.v序号
    }
  }

}
